let myApp = {
    appName: "screeps",//应用名称
    position: [0, 1500],//悬浮框的位置
    scriptFile: "./screeps_dialogs.js",//执行Dialogs脚本
    imageFile: "file://" + engines.myEngine().cwd() + "/" + "screeps.png",//悬浮框图标

    // 检查悬浮窗权限
    checkPremission: function () {
        if (!$floaty.checkPermission()) {
            // 没有悬浮窗权限，提示用户并跳转请求
            toast("本脚本需要悬浮窗权限来显示悬浮窗，请在随后的界面中允许并重新运行本脚本。");
            $floaty.requestPermission();
            exit();
        }
    },
    //初始化
    init: function () {
        this.checkPremission();
        //这里需要修改图片对应位置
        let w = floaty.rawWindow(
            <frame gravity="center">
                <img id="screeps" />
            </frame>
        );

        w.screeps.attr("src", this.imageFile)
        w.setPosition(this.position[0], this.position[1]);
        let th = this
        w.screeps.click(function () {
            engines.execScriptFile(th.scriptFile);
        })

        let offset = 0;
        let maxOffset = 25;
        setInterval(() => {
            w.setPosition(this.position[0], this.position[1] - offset);
            offset++;
            offset = offset % maxOffset;
        }, 100);
    }
}


module.exports = myApp;
